
class WatcherView extends eui.Component {
  protected watchers: eui.Watcher[];
  public closeTarget: any;
  public closeCallback: Function;
  private _currTime: number;

  constructor() {
    super();
    this.watchers = [];
    this.addEventListener(eui.UIEvent.ADDED_TO_STAGE, this.onEnter, this)
    this.addEventListener(eui.UIEvent.REMOVED_FROM_STAGE, this.dispose, this);
  }

  dispose() {
    this.onExit();

  }

  update(dt: number) {

  }

  close() {
    GameUtils.removeFromParent(this);
  }

  private onEnterFrame() {
    this.update(egret.getTimer() - this._currTime);
    this._currTime = egret.getTimer();
  }

  public onEnter() {
    this.bindDatas();
    this._currTime = egret.getTimer();
    egret.Ticker.getInstance().register(this.onEnterFrame, this);
  }

  public onExit() {
    this.unbindDatas();
    GameUtils.clearAllInterval(this);
    GameUtils.clearAllTimeout(this);
    egret.Ticker.getInstance().unregister(this.onEnterFrame, this);
  }

  /** 关注数据*/
  protected bindDatas() {

  }

  protected bindData(host: any, chains: string[], handler: (value: any) => void, thisObject: any) {
    this.watchers.push(eui.Binding.bindHandler(host, chains, handler, thisObject));
  }

  /** 清除关注的数据 */
  protected unbindDatas() {
    this.watchers.map((value: eui.Watcher) => {
      value.unwatch();
    });
    this.watchers = [];
  }
}
